#include "SpriteMario.h"

SpriteMario::SpriteMario(CL_GraphicContext gc){
	marioContext = gc;
	for(int h=0;h<FRAMES_MARIO;h++){
		resources[h]=NULL;
	}
	resources[0]= new CL_ResourceManager("MarioStanding.xml");
	resources[1] = new CL_ResourceManager("MarioRun.xml");
	resources[2] = new CL_ResourceManager("MarioJump.xml");
	resources[3] = new CL_ResourceManager("MarioClimb.xml");
	resources[4] = new CL_ResourceManager("MarioDead.xml");
	resources[5] = new CL_ResourceManager("LifePoint.xml");
	for(int i=0;i<FRAMES_MARIO;i++){
		msprites[i]=NULL;
	}
	msprites[0]=new CL_Sprite(gc, "MarioStanding", resources[0]);
	msprites[1] = new CL_Sprite(gc, "MarioRun", resources[1]);
	msprites[2] = new CL_Sprite(gc, "MarioJump", resources[2]);
	msprites[3] = new CL_Sprite(gc, "MarioClimb", resources[3]);
	msprites[4] = new CL_Sprite(gc, "MarioDead", resources[4]);
	msprites[5] = new CL_Sprite(gc, "LifePoint", resources[5]);
	isrotated = false;
}

void SpriteMario::drawstanding(CL_Vec2<int> position){
	msprites[0]->draw(marioContext,position.x, position.y);
}

void SpriteMario::drawrunning(CL_Vec2<int> position){
	msprites[1]->draw(marioContext, position.x, position.y);
	msprites[1]->update();
}

void SpriteMario::drawjumping(CL_Vec2<int> position){
	msprites[2]->draw(marioContext, position.x, position.y);
}

void SpriteMario::drawclimbing(CL_Vec2<int> position)
{
	msprites[3]->draw(marioContext, position.x, position.y);
}

void SpriteMario::drawdead(CL_Vec2<int> position)
{
	msprites[4]->draw(marioContext, position.x, position.y);
}

void SpriteMario::drawhud(int lifes)
{
	if(lifes >= 1)
	{
		msprites[5]->draw(marioContext, 530, 30);
	}
	if(lifes >= 2)
	{
		msprites[5]->draw(marioContext, 512, 30);
	}
	if(lifes >= 3)
	{
		msprites[5]->draw(marioContext, 494, 30);
	}
}

SpriteMario::~SpriteMario(){
	for each(CL_Sprite* s in msprites){
		if(s!=NULL){
			delete s;
			s=NULL;
		}
		
	}
	for each(CL_ResourceManager* rs in resources){
		if(rs!=NULL){
			delete rs;
			rs=NULL;
		}
		
	}
}